<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item>轮播图管理</el-breadcrumb-item>
    <el-breadcrumb-item>轮播图列表</el-breadcrumb-item>
  </el-breadcrumb>

  <el-table :data="tableData" style="width: 100%">
    <el-table-column label="序号">
      <template #default="scope">
        <span>{{ scope.$index }}</span>
      </template>
    </el-table-column>
    <el-table-column label="图片">
      <template #default="scope">
        <!-- scope.row表示一整条数据（一个对象） -->
        <!-- <span>{{ scope.row.img }}</span> -->
        <!-- <img :src="scope.row.img" alt="" /> -->
        <!-- <span>{{ scope.$index }}</span> -->
        <el-image
          style="width: 100px; height: 100px"
          :src="scope.row.img"
          :preview-src-list="[scope.row.img]"
          fit="cover"
          :preview-teleported="true"
        />
      </template>
    </el-table-column>
    <el-table-column prop="link" label="链接" />
    <el-table-column prop="alt" label="提示" />
    <el-table-column label="操作">
      <template #default="scope">
        <!-- <el-button type="danger">删除</el-button> -->

        <el-popconfirm
          title="确定要删除吗?"
          @confirm="remove(scope.row.bannerid)"
        >
          <template #reference>
            <el-button type="danger">删除</el-button>
          </template>
        </el-popconfirm>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import axios from "axios";
import { ElMessage } from "element-plus";
// import http from "@/utils/http";
import { getBannerApi, removeBannerApi } from "@/api/banner";

const tableData = ref([]);
onMounted(() => {
  getData();
});

const getData = async () => {
  const res = await getBannerApi();
  if (res) {
    tableData.value = res.data;
  }

  // getBannerApi().then((res: any) => {
  //   if (res) {
  //     tableData.value = res.data;
  //   }
  // });
  // axios
  //   .get("http://121.89.205.189:3000/admin/banner/list", {
  //     params: {},
  //     headers: {
  //       "Content-Type": "application/json",
  //       token: sessionStorage.getItem("token"),
  //     },
  //   })
  //   .then((res) => {
  //     if (res.data.code === "200") {
  //       tableData.value = res.data.data;
  //     }
  //   });
};

const remove = async (id: string) => {
  const res = await removeBannerApi({ bannerid: id });
  if (res) {
    ElMessage({
      message: "删除数据成功",
      type: "success",
    });
    getData();
  }

  // console.log("remove");
  // axios
  //   .get("http://121.89.205.189:3000/admin/banner/delete", {
  //     params: {
  //       bannerid: id,
  //     },
  //     headers: {
  //       "Content-Type": "application/json",
  //       token: sessionStorage.getItem("token"),
  //     },
  //   })
  //   .then((res) => {
  //     if (res.data.code === "200") {
  //       ElMessage({
  //         message: "删除数据成功",
  //         type: "success",
  //       });
  //       getData();
  //     }
  //   });
  // removeBannerApi({
  //   bannerid: id,
  // }).then((res) => {
  //   if (res) {
  //     ElMessage({
  //       message: "删除数据成功",
  //       type: "success",
  //     });
  //     getData();
  //   }
  // });
};
</script>

<style lang="less" scoped></style>
